import { createBrowserRouter } from 'react-router-dom';
import App from '../App';
import Home from '../pages/Home';

import Resources from '../pages/Resources';
import { CommunityPage } from '../pages/CommunityPage';
import { UserPostsPage } from '../pages/UserPostsPage';
import Profile from '../pages/Profile';
import Notification from '../pages/Notification';
import LoginForm from '../features/auth/components/LoginForm';
import RegisterForm from '../features/auth/components/RegisterForm';
import UserTagSelection from '../features/auth/components/UserTagSelection';
import DownloadHistory from '../features/resources/components/DownloadHistory';
import PurchaseHistory from '../features/resources/components/PurchaseHistory';
import FriendList from '../features/friends/components/FriendList';
import ResourceDetail from '../features/resources/pages/ResourceDetail';
import PromotionPage from '../features/promotion/pages/PromotionPage';
import MyResources from '../features/resources/pages/MyResources';
//import ResourceUploader from '../features/resources/components/ResourceUploader';
import AdminPage from '../features/admin/pages/AdminPage';
import ProtectedRoute from './ProtectedRoute';

const router = createBrowserRouter([
  {
    path: '/',
    element: <App />,
    children: [
      {
        path: '/',
        element: <Home />,
      },
      {
        path: '/login',
        element: <LoginForm />,
      },
      {
        path: '/register',
        element: <RegisterForm />,
      },
      {
        path: '/tag-selection',
        element: <UserTagSelection />,
      },
      // 受保护的路由
      {
        element: <ProtectedRoute />,
        children: [
          {
            path: '/resources',
            element: <Resources />,
            children: [
              {
                path: ':id',
                element: <ResourceDetail />,
              },
              {
                path: 'promotion/:promotionId',
                element: <ResourceDetail isPromotion={true} />,
              },
            ],
          },
          {
            path: '/community',
            element: <CommunityPage />,
          },
          {
            path: '/my-posts',
            element: <UserPostsPage />,
          },
          {
            path: '/profile',
            element: <Profile />,
          },
          {
            path: '/profile/:username',
            element: <Profile />,
          },
          {
            path: '/notification',
            element: <Notification />,
          },
          {
            path: '/downloads',
            element: <DownloadHistory />,
          },
          {
            path: '/purchases',
            element: <PurchaseHistory />,
          },
          {
            path: '/friends',
            element: <FriendList />,
          },
          {
            path: '/promotions',
            element: <PromotionPage />,
          },
          {
            path: '/admin',
            element: <AdminPage />,
          },
          {
            path: '/my-resources',
            element: <MyResources />,
          },
        ],
      },
    ],
  },
]);

export default router;